package com.tanhua.manage.controller;

import com.tanhua.manage.service.AnalysisByDayService;
import com.tanhua.manage.service.RetentionldService;
import com.tanhua.manage.vo.PageResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @刘波
 * @2021/9/12 15:26
 */
@RestController
@RequestMapping("daydate")
public class AnalysisByDayController {

    @Autowired
    private AnalysisByDayService analysisByDayService;

    @Autowired
    private RetentionldService retentionldService;

    @GetMapping("save")
    public ResponseEntity<PageResult> queryDayDate(@RequestParam("sd") Long startTime,
                                                   @RequestParam("ed") Long endTime
            , @RequestParam("gender") String gender
            , @RequestParam("page") Integer page
            , @RequestParam("pagesize") Integer pageSize
    ){
        try {
            PageResult pageResult = analysisByDayService.queryDayByDate(startTime,endTime,gender,page,pageSize);
            return ResponseEntity.ok(pageResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping("check")
    public ResponseEntity<PageResult> queryCheck(@RequestParam("sd") Long startTime
                                                 ,@RequestParam("ed") Long endTime
                                                 , @RequestParam("gender") String gender
                                                 , @RequestParam("page") Integer page
                                                 , @RequestParam("pagesize") Integer pageSize){
        try {
            PageResult pageResult = retentionldService.queryCheck(startTime,endTime,gender,page,pageSize);
            return ResponseEntity.ok(pageResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
